
class Main extends eui.UILayer {

    protected createChildren(): void {
        super.createChildren();
        egret.lifecycle.addLifecycleListener((context) => {
        });

        egret.lifecycle.onPause = () => {
            egret.ticker.pause();
        };

        egret.lifecycle.onResume = () => {
            egret.ticker.resume();
        };


        //注入自定义的素材解析器
        egret.registerImplementation("eui.IAssetAdapter", new AssetAdapter());
        egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter());

        this.start().catch(e => {
            console.log(e);
        });
    }

    private async start() {
        await this.loadResource(); 
         
        this.addChild(new SelectPage);
    }

    private async loadResource() {
        try {
            const loadingPage = new LoadingUI;
            this.addChild(loadingPage);
            await RES.loadConfig("resource/default.res.json", "resource/");

            await new Promise((resolve, reject) => { 
                let theme = new eui.Theme("resource/default.thm.json", this.stage);
                theme.addEventListener(eui.UIEvent.COMPLETE, () => {
                    resolve();
                }, this);

            });

            await RES.loadGroup("preload", 0, loadingPage);
 
            egret.Tween.get(loadingPage).to({ alpha: 0 }, 300).call(() => {
                this.removeChild(loadingPage);
            });

        }
        catch (e) {
            console.error(e);
        }
 
    } 

}
